﻿package com.vicentediaz.view.leftrightbuttons
{
    import com.myp.flow.*;
    import com.myp.mystage.*;
    import com.vicentediaz.data.*;
    import com.vicentediaz.flow.*;
    import com.vicentediaz.view.imageviewer.*;
    import flash.display.*;
    import flash.events.*;

    public class LeftRightButtons extends Sprite
    {
        private var left:ButtonLeft;
        private var right:ButtonLeft;

        public function LeftRightButtons()
        {
            addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage, false, 0, true);
            return;
        }// end function

        private function onAddedToStage(param1:Event) : void
        {
            this.left = new ButtonLeft();
            this.right = new ButtonLeft();
            this.right.scaleX = -1;
            addChild(this.left);
            addChild(this.right);
            this.left.show();
            this.right.show();
            this.left.addEventListener(MouseEvent.CLICK, this.onLeftClick, false, 0, true);
            this.right.addEventListener(MouseEvent.CLICK, this.onRightClick, false, 0, true);
            MyStage.getInstance().stage.addEventListener(Event.RESIZE, this.onResize, false, 0, true);
            this.onResize(null);
            return;
        }// end function

        private function showImage(param1:int) : void
        {
            param1 = param1 < 0 ? (Gallery.getInstance().loadedThumbs--) : (param1);
            param1 = param1 >= Gallery.getInstance().loadedThumbs ? (0) : (param1);
            if (Flow.level(MainFlow.LEVEL).currentSection != MainFlow.IMAGEN)
            {
                Flow.level(MainFlow.LEVEL).request(MainFlow.IMAGEN, "LeftRightButtons");
            }// end if
            Flow.level(ImageFlow.LEVEL).request(param1.toString(), "LeftRightButtons");
            return;
        }// end function

        private function onLeftClick(param1:MouseEvent) : void
        {
            this.showImage(ImageViewer.getInstance().currentImageId--);
            Sounds.getInstance().playById("CLICK_IMAGE", 1, (-(stage.stageWidth / 2 - mouseX)) / stage.stageWidth);
            return;
        }// end function

        private function onResize(param1:Event) : void
        {
            this.left.x = 0;
            this.right.x = MyStage.getInstance().width;
            this.left.y = MyStage.getInstance().centerY - 10;
            this.right.y = MyStage.getInstance().centerY - 10;
            return;
        }// end function

        private function onRightClick(param1:MouseEvent) : void
        {
            this.showImage(ImageViewer.getInstance().currentImageId + 1);
            Sounds.getInstance().playById("CLICK_IMAGE", 1, (-(stage.stageWidth / 2 - mouseX)) / stage.stageWidth);
            return;
        }// end function

    }
}
